package com.teach;

import java.io.File;
import java.util.Date;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;

public class FileTest1 {

	public static void main(String[] args) {
		File root = new File("d:\\upload");

		// 文件和文件夹的属性
		File file = new File(root,"a.txt");
//		file = new File("a.txt");
		System.out.println(file.getAbsolutePath());
		System.out.println(file.getPath());
		
		System.out.println(file.getParent());
		System.out.println(file.getParentFile());
		System.out.println(root.getParentFile());
		System.out.println(file.getParentFile().getParentFile());
		System.out.println(file.getParentFile().getParentFile().getParentFile());
		
		System.out.println(file.getName());
		System.out.println(root.getName());
		
		System.out.println(file.length());
		System.out.println(root.length());//不推荐使用，目录大小

		System.out.println(FileUtil.size(file));
		System.out.println(FileUtil.size(root));

		//自己写的工具类
		System.out.println(com.teach.util.FileUtil.getSizeDescribe(file.length()));
		System.out.println(com.teach.util.FileUtil.getSizeDescribe(root.length()));
		
		//自己写的工具类
		System.out.println(com.teach.util.FileUtil.getFileExt(file.getName()));
		System.out.println(FileUtil.extName(file));
		System.out.println(FileUtil.extName(root));
		
		System.out.println("-------------------------");
		System.out.println(file.getFreeSpace());
		System.out.println(file.getTotalSpace());
		System.out.println(file.getUsableSpace());

		System.out.println(com.teach.util.FileUtil.getSizeDescribe(file.getFreeSpace()));
		System.out.println(com.teach.util.FileUtil.getSizeDescribe(file.getTotalSpace()));
		System.out.println(com.teach.util.FileUtil.getSizeDescribe(file.getUsableSpace()));
		
		System.out.println("--------存在 文件夹？文件？-----------------");
		File f1 = new File(root,"c.txt");
		System.out.println(root.exists());
		System.out.println(file.exists());
		System.out.println(f1.exists());

		System.out.println(root.isFile());
		System.out.println(file.isFile());
		System.out.println(f1.isFile());

		System.out.println(root.isDirectory());
		System.out.println(file.isDirectory());
		System.out.println(f1.isDirectory());

		System.out.println("--------权限？-----------------");
		System.out.println("是否可执行:"+file.canExecute());
		System.out.println("是否可读："+file.canRead());
		System.out.println("是否可写："+file.canWrite());

		System.out.println("是否可执行:"+root.canExecute());
		System.out.println("是否可读："+root.canRead());
		System.out.println("是否可写："+root.canWrite());
		
		
		System.out.println("-------------最后修改时间--------------");
		System.out.println(file.lastModified());
		System.out.println(new Date(file.lastModified()));
	}
}
